package com.example.boot.rtgoods.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.example.boot.rtgoods.dao.RtGoodsDao;
import com.example.boot.rtgoods.model.RtGoods;
import com.example.boot.rtgoods.service.RtGoodsService;
import com.example.boot.rtgoods.vo.GoodsType;
import com.example.boot.rtnotice.dao.RtNoticeDao;
import com.example.boot.rtnotice.model.RtNotice;
import com.example.boot.rtshop.dao.RtShopDao;
import com.example.boot.rtshop.model.RtShop;
import com.example.boot.rtshopactivity.dao.RtShopActivityDao;
import com.example.boot.rtshopactivity.model.RtShopActivity;
import com.example.boot.rttable.dao.RtTableDao;
import com.example.boot.rttable.model.RtTable;

@Service
public class RtGoodsImpl implements RtGoodsService {
	@Autowired
	private RtGoodsDao rtGoodsDao;
	@Autowired
	private RtShopDao rtShopDao;
	@Autowired
	private RtShopActivityDao shopActivityDao;
	@Autowired
	private RtNoticeDao noticeDao;
	@Autowired
	private RtTableDao rtTableDao;
	@Override
	public RtShop byTableIdFindGoods(String tableId) throws Exception {
		RtTable selectByPrimaryKey = rtTableDao.selectByPrimaryKey(tableId);
		RtShop byTableIdFindShop = rtShopDao.byTableIdFindShop(tableId);
		String shopId= byTableIdFindShop.getId();
		List<GoodsType> byShopFindGoodsType = rtGoodsDao.byShopFindGoodsType(byTableIdFindShop.getId());
		List<RtGoods> findByAllGoods = rtGoodsDao.findByAllGoods(shopId);
		List<RtShopActivity> byShopIdFindActivity = shopActivityDao.byShopIdFindActivity(shopId);
		List<RtNotice> byShopIdFindNotice = noticeDao.byShopIdFindNotice(shopId);

		// List<List<RtGoods>> list = new ArrayList<>();
//		for (GoodsType g : byShopFindGoodsType) {
//			List<RtGoods> byTypeIdFindGoods = rtGoodsDao.byTypeIdFindGoods(g.getTypeId(),shopId);
//			g.setGoodsList(byTypeIdFindGoods);
//		}
		byTableIdFindShop.setTableNo(selectByPrimaryKey.getTableNo());
		byTableIdFindShop.setGoodsType(byShopFindGoodsType);
		byTableIdFindShop.setGoodsList(findByAllGoods);
		byTableIdFindShop.setActivityList(byShopIdFindActivity);
		byTableIdFindShop.setNoticeList(byShopIdFindNotice);

		// byTableIdFindShop.setGoodsType(list);
		

		return byTableIdFindShop;
	}

	@Override
	public RtShop byShopIdFindGoods(String shopId) throws Exception {
		RtShop rtShop = rtShopDao.selectByPrimaryKey(shopId);
		List<GoodsType> byShopFindGoodsType = rtGoodsDao.byShopFindGoodsType(shopId);
		List<RtGoods> findByAllGoods = rtGoodsDao.findByAllGoods(shopId);
		List<RtShopActivity> byShopIdFindActivity = shopActivityDao.byShopIdFindActivity(shopId);
		List<RtNotice> byShopIdFindNotice = noticeDao.byShopIdFindNotice(shopId);
//		for (GoodsType g : byShopFindGoodsType) {
//			g.setGoodsList(byTypeIdFindGoods);
//		}
//		List<RtGoods> byTypeIdFindGoods = rtGoodsDao.byTypeIdFindGoods(g.getTypeId(),shopId);
		
		rtShop.setGoodsList(findByAllGoods);
		rtShop.setGoodsType(byShopFindGoodsType);
		rtShop.setActivityList(byShopIdFindActivity);
		rtShop.setNoticeList(byShopIdFindNotice);
		return rtShop;
	}

}
